package com.chixing.controller;

import com.chixing.commons.UploadImgUtil;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 * 上传附件表 前端控制器
 * </p>
 *
 * @author Jason Marslyon
 * @since 2022-10-04
 */
@Controller
@RequestMapping("/uploadResume")
public class UploadResumeController {
    //上传简历
    @RequestMapping("/upload")
    @ResponseBody
    public Map upload(@RequestParam("file") MultipartFile myfile) { // 文件接收对象
        Map map = new HashMap<>();
        try {
            String fileUrl = UploadImgUtil.upload(myfile.getBytes(),myfile.getOriginalFilename());
            map.put("fileUrl", fileUrl);
            System.out.println(">>>>>>>>>"+map);
        } catch (IOException e) {
            e.printStackTrace();
            map.put("fileUrl", null);
        }
        return map;

    }

    //  上传头像
    @RequestMapping("/uploadImg")
    @ResponseBody
    public Map uploadImg(@RequestParam("file") MultipartFile myfile) { // 文件接收对象
        Map map = new HashMap<>();
        try {
            String imgUrl = UploadImgUtil.upload(myfile.getBytes(),myfile.getOriginalFilename());
            map.put("imgUrl", imgUrl);
            System.out.println(">>>>>>>>>"+map);
        } catch (IOException e) {
            e.printStackTrace();
            map.put("imgUrl", null);
        }
        return map;

    }
}
